﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using IHISCETeim.Library;
using System.Data.Common;
using Microsoft.Practices.EnterpriseLibrary.Data;
using Microsoft.Practices.EnterpriseLibrary.Data.Sql;
using IHISCETeim.Model;
namespace IHISCETeim.DAL
{
    public  class MAgentAddressDAL
    {
        public static int Add(MAgentAddressInfo obj)
        {
            Database DB = DatabaseFactory.CreateDatabase();

            DbCommand dbCommand = DB.GetStoredProcCommand("MAgentAddress_Add", obj.CardCode, obj.Address, obj.LinkeName, obj.Tel1, obj.ShowIndex);
            return Convert.ToInt32(DB.ExecuteScalar(dbCommand));
        }
        public static bool Delete(int MAAID)
        {
            Database DB = DatabaseFactory.CreateDatabase();
            DbCommand dbCommand = DB.GetStoredProcCommand("MAgentAddress_Delete", MAAID);
            try
            {
                DB.ExecuteScalar(dbCommand);
                return true;
            }
            catch
            {
                return false;
            }
        }
        public static DataTable GetAllByCardCode(string CardCode)
	    {
		    Database DB = DatabaseFactory.CreateDatabase();		
		
		    DbCommand dbCommand = DB.GetStoredProcCommand("MAgentAddress_GetAllByCardCode", CardCode);
            return DB.ExecuteDataSet(dbCommand).Tables[0];
	    }
        public static IDataReader GetById(int MAAID)
	    {
		    Database DB = DatabaseFactory.CreateDatabase();		
		
            DbCommand dbCommand = DB.GetStoredProcCommand("MAgentAddress_GetById", MAAID);
            return DB.ExecuteReader(dbCommand);
	    }
        public static bool Update(MAgentAddressInfo obj)
        {
            Database DB = DatabaseFactory.CreateDatabase();

            DbCommand dbCommand = DB.GetStoredProcCommand("MAgentAddress_Update", obj.MAAID, obj.Address, obj.LinkeName, obj.Tel1, obj.ShowIndex);
           
            try
            {
                DB.ExecuteScalar(dbCommand);
                return true;
            }
            catch (Exception exc)
            {
                return false;
            }
        }
    }
}
